<?php
/*
 * Created on Feb 19, 2010
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
class MyEStateModel{	
	
	function MyEStateModel(){
	
	}
	
	function getReesById($id = null){
		global $connDB;  //The database connection
		if($id == null) return null;
		$sql = "SELECT * FROM ".TBL_ITEM." WHERE id = '$id' AND deleteFlag = 0";
		$result = $connDB->DB_query($sql,$connDB->connection);		
		return $connDB->DB_fetch_array($result);
	}		
	
	function getCountItems($userId = null){		
		global $connDB;  
		if ($userId == null) {
			
			return 0;
		}
		$sql =	" SELECT *".
				" FROM ". TBL_ITEM .' item '.
				" WHERE item.deleteFlag = 0 AND item.rees_user_id = $userId";  
		$result = $connDB->DB_query($sql, $connDB->connection);
		
      	return $connDB->DB_num_rows($result);
	}
	
	function getMyItems($userId = null, $offset = null, $limit = null) {
		global $connDB;  
		if ($userId == null) {
			
			return null;
		}
		$sql =	" SELECT item.*, city.`name` as city_name, district.`name` as district_name  ".
				" FROM ". TBL_ITEM .' item '.
				" LEFT JOIN ". TBL_CITY ." city ON item.`rees_city_id` = city.`id` ".
				" LEFT JOIN ". TBL_DISTRICT ." district ON item.`rees_district_id` = district.`id` ".
				" WHERE item.deleteFlag = 0 AND item.rees_user_id = ".$userId." ".
				" ORDER BY item.updateDate DESC, item.title ASC ".getLimitFormat($offset, $limit);  
		$result = $connDB->DB_query($sql, $connDB->connection);
		
      	return $result;
	}
	
	function getArrayNameItem($resultSet = null){
		global $connDB;  
		if($resultSet == null) {
			
			return null;
		}
		
		return $connDB->DB_fetch_array($resultSet);
	}
} 

/* Create cityregion controller object */
$myestateModel = new MyEStateModel;
?>